package com.persondemo.videoappliction.ui.vip.presenter;

import com.persondemo.videoappliction.bean.DelteShopBean;
import com.persondemo.videoappliction.bean.MeShopBean;
import com.persondemo.videoappliction.net.BaseApi;
import com.persondemo.videoappliction.net.BaseObserver;
import com.persondemo.videoappliction.net.RxSchedulers;
import com.persondemo.videoappliction.ui.base.BasePresenter;
import com.persondemo.videoappliction.ui.vip.contract.MeShopContract;

import javax.inject.Inject;

public class MeShopPresenter extends BasePresenter<MeShopContract.View> implements MeShopContract.Presenter {
    private BaseApi baseApi;

    @Inject
    public MeShopPresenter(BaseApi baseApi) {
        this.baseApi = baseApi;
    }

    @Override
    public void getshop(String device, String page) {
        baseApi.meshops(device, page)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<MeShopBean>() {
                    @Override
                    public void onSuccess(MeShopBean meShopBean) {
                        if (page.equals("1")) {
                            mView.loadshop(meShopBean);
                        } else {
                            mView.loadmore(meShopBean);
                        }
                    }

                    @Override
                    public void onFail(Throwable e) {

                    }
                });
    }

    @Override
    public void delteshop(String device, String id) {
        baseApi.delteshop(device, id)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<DelteShopBean>() {
                    @Override
                    public void onSuccess(DelteShopBean delteShopBean) {
                        mView.loaddetle(delteShopBean);
                    }

                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }
}
